#scrap index : https://www.tutorialspoint.com/index.htm
from bs4 import BeautifulSoup
import re
from urllib.request import urlopen
from pymongo import MongoClient

client = MongoClient('mongodb://localhost:20000/')
db = client['ddbwork']

def getTopClasses(index_url):
    topclass=db['topclass']
    html = urlopen(index_url)
    bsObj = BeautifulSoup(html, 'html.parser')
    h4s = bsObj.find('div',{'class':'row featured-boxes'}).findAll('h4')
    for h4 in h4s:
        topclass = h4.get_text()
        db.topclass.insert_one({"name":topclass})
        print(topclass)
        print('----')
        


index_url='https://www.tutorialspoint.com/index.htm'
getTopClasses(index_url)
cur = db.topclass.find()
for c in cur:
    print(c['name'])
